package com.lvwenguo.controller.category;

import com.lvwenguo.service.CategoryListServiceInter;
import com.lvwenguo.service.serviceImple.CategoryListServiceImple;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//修改商品
@WebServlet(urlPatterns = "/UpdateCategory")
public class UpdateCategory extends HttpServlet {
    CategoryListServiceInter categoryListServiceImpol =new CategoryListServiceImple();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String categoryName = req.getParameter("categoryName");
        if(categoryName.equals("") || categoryName==null){
            req.setAttribute("error","内容为空");
            req.getRequestDispatcher("/view/category/category_modify.jsp").forward(req,resp);
        }
        else{
            int i = categoryListServiceImpol.AddCategory(categoryName);
            if(i!=0){
                req.getRequestDispatcher("/CategoryListServlet").forward(req,resp);
            }
            else{
                req.setAttribute("error","名称重复");
                req.getRequestDispatcher("/view/category/category_modify.jsp").forward(req,resp);
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
